public class SyncMethod implements Runnable{

    private int count = 5;

    public void run(){
        for(int i = 0; i < 10; i++){
            sale();
        }
    }

    // sync method
    private synchronized void sale(){
        if(count > 0){
            try{
                Thread.sleep(1000);
            }catch(Exception e){
                e.printStackTrace();
            }
            
            System.out.println(Thread.currentThread().getName() + " : " + count--);
        }
    }

    public static void main(String[] args){

        SyncMethod sm = new SyncMethod();
        Thread t1 = new Thread(sm);
        Thread t2 = new Thread(sm);
        Thread t3 = new Thread(sm);

        t2.start();
        t1.start();
        t3.start();

    }

}